//
//  AddressCell.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/8/25.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "AddressCell.h"



@interface AddressCell()


@property(nonatomic,strong)UILabel * l1;
@property(nonatomic,strong)UILabel * l2;
@property(nonatomic,strong)UILabel * l3;
@property(nonatomic,strong)UILabel * l4;
@property(nonatomic,strong)UILabel * l5;
@property(nonatomic,strong)UIImageView * imgv1;
@property(nonatomic,strong)UIImageView * imgv2;

@end
@implementation AddressCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.cellHeight = 70;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UIImageView * backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(globalMargin, 0, ScreenWidth-2*globalMargin, self.cellHeight)];
        backgroundImageView.image = [UIImage imageWithColor:[UIColor whiteColor] size:backgroundImageView.size];
        [self.contentView insertSubview:backgroundImageView atIndex:0];
        [backgroundImageView addRadius:10];
        
        
        self.l1 = [self creatLabelWithFont:[UIFont systemFontOfSize:17]];
        [self.contentView addSubview:self.l1];
        
        self.l2 = [self creatLabelWithFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:self.l2];
        
        self.l3 = [self creatLabelWithFont:[UIFont systemFontOfSize:13]];
        self.l3.textAlignment = NSTextAlignmentCenter;
        self.l3.backgroundColor = [UIColor orangeColor];
        self.l3.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.l3];
        
        self.l4 = [self creatLabelWithFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:self.l4];
        
        self.l5 = [self creatLabelWithFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:self.l5];
        
        
        
        self.imgv1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"address"]];
        [self.contentView addSubview:self.imgv1];
        self.imgv2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"decoration"]];
        [self.contentView addSubview:self.imgv2];
        

    }
    return self;
}
-(UILabel*)creatLabelWithFont:(UIFont*)font{
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = font;
    label.textColor = [UIColor blackColor];
    return label;
}

-(void)setAddress:(id )address{
    _address = address;
    [self setNeedsLayout];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    

    self.l1.text = [self.address objectForKey:@"ship_name"];
    self.l2.text = [self.address objectForKey:@"ship_mobile"];
    self.l3.text = @"默认";
    self.l4.text = @"收货地址:";
    self.l5.text = [self.address objectForKey:@"ship_addr"];
    

    
    self.imgv2.size = self.imgv2.image.size;
    self.imgv2.x = globalMargin;
    self.imgv2.y = self.cellHeight - self.imgv2.height;
    
    self.imgv1.x = 2*globalMargin;
    self.imgv1.y = self.cellHeight-self.imgv1.height - self.imgv2.height-5;
    self.imgv1.size = self.imgv1.image.size;
    
    self.l4.x = self.imgv1.right+5;
    self.l4.centerY = self.imgv1.centerY;
    self.l4.size = [self.l4.text sizeInAre:MaxSize font:self.l4.font];
    
    self.l5.x = self.l4.right+5;
    self.l5.y = self.l4.y;
    self.l5.size = [self.l5.text sizeInAre:MaxSize font:self.l5.font];
    self.l5.width = ScreenWidth - self.l4.right - 2*globalMargin-5;
    
    self.l1.x = 2*globalMargin;
    self.l1.y = globalMargin;
    self.l1.size = [self.l1.text sizeInAre:MaxSize font:self.l1.font];
    
    self.l2.size = [self.l2.text sizeInAre:MaxSize font:self.l2.font];
    self.l2.x = self.l1.right + 5;
    self.l2.y = self.l1.botton - self.l2.height;
    
    
    self.l3.size = [self.l3.text sizeInAre:MaxSize font:self.l3.font];
    self.l3.width+=8;
    self.l3.height+=2;
    [self.l3 addRadius:4];
    
    self.l3.x = self.l2.right+5;
    self.l3.centerY = self.l1.centerY;
    

}

-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
}
@end
